# Copyright 2024 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//build_tools/bazel:build_defs.oss.bzl", "iree_compiler_cc_library", "iree_gentbl_cc_library", "iree_tablegen_doc", "iree_td_library")
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

exports_files([
    "IREEGPUAttrs.td",
    "IREEGPUDialect.td",
    "IREEGPUEnums.td",
    "IREEGPUInterfaces.td",
])

iree_td_library(
    name = "td_files",
    srcs = enforce_glob(
        [
            "IREEGPUAttrs.td",
            "IREEGPUDialect.td",
            "IREEGPUEnums.td",
            "IREEGPUInterfaces.td",
            "IREEGPUOps.td",
        ],
        include = ["*.td"],
    ),
    deps = [
        "//compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR:td_files",
        "@llvm-project//mlir:ControlFlowInterfacesTdFiles",
        "@llvm-project//mlir:DialectUtilsTdFiles",
        "@llvm-project//mlir:OpBaseTdFiles",
        "@llvm-project//mlir:SCFTdFiles",
        "@llvm-project//mlir:SideEffectInterfacesTdFiles",
        "@llvm-project//mlir:TilingInterfaceTdFiles",
        "@llvm-project//mlir:VectorInterfacesTdFiles",
    ],
)

iree_compiler_cc_library(
    name = "IREEGPUDialect",
    srcs = [
        "DerivedConfigUtils.cpp",
        "GPULoweringConfigUtils.cpp",
        "GPUTileSwizzleUtils.cpp",
        "IREEGPUAttrs.cpp",
        "IREEGPUDialect.cpp",
        "IREEGPUInterfaces.cpp",
        "IREEGPUOps.cpp",
        "TilingInterfaceImpl.cpp",
    ],
    hdrs = [
        "DerivedConfigUtils.h",
        "GPULoweringConfigUtils.h",
        "GPUTileSwizzleUtils.h",
        "IREEGPUAttrs.h",
        "IREEGPUDialect.h",
        "IREEGPUEnums.h",
        "IREEGPUInterfaces.h",
        "IREEGPUOps.h",
    ],
    textual_hdrs = [
        "IREEGPUAttrs.cpp.inc",
        "IREEGPUAttrs.h.inc",
        "IREEGPUDialect.cpp.inc",
        "IREEGPUDialect.h.inc",
        "IREEGPUEnums.cpp.inc",
        "IREEGPUEnums.h.inc",
        "IREEGPUInterfaces.cpp.inc",
        "IREEGPUInterfaces.h.inc",
        "IREEGPUOps.cpp.inc",
        "IREEGPUOps.h.inc",
    ],
    deps = [
        ":IREEGPUAttrs",
        ":IREEGPUDialectGen",
        ":IREEGPUEnums",
        ":IREEGPUInterfaces",
        ":IREEGPUOpsGen",
        "//compiler/bindings/c:headers",
        "//compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR:IREECodegenDialect",
        "//compiler/src/iree/compiler/Codegen/Dialect/Codegen/Utils",
        "//compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR:IREEVectorExtDialect",
        "//compiler/src/iree/compiler/Codegen/Utils:VectorOpUtils",
        "//compiler/src/iree/compiler/Dialect/LinalgExt/IR",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:AMDGPUDialect",
        "@llvm-project//mlir:AffineDialect",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:ArithUtils",
        "@llvm-project//mlir:CAPIIR",
        "@llvm-project//mlir:ControlFlowInterfaces",
        "@llvm-project//mlir:DialectUtils",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:LinalgDialect",
        "@llvm-project//mlir:Parser",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:SideEffectInterfaces",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TilingInterface",
        "@llvm-project//mlir:VectorDialect",
        "@llvm-project//mlir:VectorInterfaces",
    ],
)

iree_gentbl_cc_library(
    name = "IREEGPUDialectGen",
    tbl_outs = [
        (
            ["--gen-dialect-decls"],
            "IREEGPUDialect.h.inc",
        ),
        (
            ["--gen-dialect-defs"],
            "IREEGPUDialect.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREEGPUDialect.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "IREEGPUEnums",
    tbl_outs = [
        (
            ["--gen-enum-decls"],
            "IREEGPUEnums.h.inc",
        ),
        (
            ["--gen-enum-defs"],
            "IREEGPUEnums.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREEGPUEnums.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "IREEGPUAttrs",
    tbl_outs = [
        (
            ["--gen-attrdef-decls"],
            "IREEGPUAttrs.h.inc",
        ),
        (
            ["--gen-attrdef-defs"],
            "IREEGPUAttrs.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREEGPUAttrs.td",
    deps = [
        ":td_files",
        "@llvm-project//mlir:SCFDeviceMappingInterfacesIncGen",
    ],
)

iree_gentbl_cc_library(
    name = "IREEGPUInterfaces",
    tbl_outs = [
        (
            ["--gen-attr-interface-decls"],
            "IREEGPUInterfaces.h.inc",
        ),
        (
            ["--gen-attr-interface-defs"],
            "IREEGPUInterfaces.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREEGPUInterfaces.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "IREEGPUOpsGen",
    tbl_outs = [
        (
            ["--gen-op-decls"],
            "IREEGPUOps.h.inc",
        ),
        (
            ["--gen-op-defs"],
            "IREEGPUOps.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREEGPUOps.td",
    deps = [
        ":td_files",
    ],
)

iree_tablegen_doc(
    name = "IREEGPUDialectDocGen",
    tbl_outs = [
        (
            [
                "--gen-dialect-doc",
                "--dialect=iree_gpu",
            ],
            "IREEGPUDialect.md",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREEGPUOps.td",
    deps = [":td_files"],
)
